<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <link href="css/style.css" rel="stylesheet" type="text/css"/>
    <script src="js/vue.min.js"></script>
    <script src="js/axios.min.js"></script>
    <style>
        .formtitle b {
            margin-left: 80px;
        }

        .toolsli td {
            width: 80px;
        }
        .toolsli input{
            border: 1px solid;
        }
    </style>
</head>

<body>

<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">首页</a></li>
        <li><a href="#">工具箱</a></li>
    </ul>
</div>

<div class="formbody" id="add_menu">
    <div class="formtitle"><span>基本信息</span></div>
    <div class="toolsli">
        <table>
            <tr>
                <td>文章标题</td>
                <td>
                    <select v-model="id">
                        <option value="-1" >选择一级菜单</option>
                        <option :value="menu.id" v-for="menu in menuList">{{menu.pername}}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>菜单名称</td>
                <td>
                    <input type="text" v-model="pername"/>
                </td>
            </tr>
            <tr>
                <td>菜单描述</td>
                <td>
                    <input type="text" v-model="perdesc"/>
                </td>
            </tr>
            <tr>
                <td>请求地址</td>
                <td>
                    <input type="text" v-model="url"/>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <button @click="addMenu()" style="background-color: #00a4ac;color: whitesmoke">确认保存</button>
                </td>
            </tr>
        </table>
    </div>
</div>
<script>
    var vm = new Vue({
        el: "#add_menu",
        data: {
            menuList: [],
            pername: '',
            perdesc: '',
            url: '',
            id: '-1'
        },
        created() {
            this.initMenuInfo();
        },
        methods: {
            initMenuInfo: function () {
                axios.get("/findMenuInfo").then(function (obj) {
                    var reslut = obj.data;
                    if (reslut.code == 200) {
                        vm.menuList = reslut.object;
                    }
                }).catch(function (obj) {
                    alert("查询异常");
                });
            },
            addMenu: function () {
                var param = {id: vm.id, pername: vm.pername, perdesc: vm.perdesc, url: vm.url}
                axios.post("/addMenu", param).then(function (obj) {
                    var reslut = obj.data;
                    if (reslut.code == 200) {
                        alert("添加成功！")
                        location.href = "/role_rbac.html";
                    }
                }).catch(function (obj) {
                    alert("添加异常");
                });
            }
        }
    });
</script>
</body>
</html>
